from django.db import models
# from django.contrib.auth.models import User
# from django.contrib.auth.models import AbstractUser


class TbSite(models.Model):
    site_code = models.CharField(max_length=50)
    site_name = models.CharField(max_length=50)
    area_code = models.CharField(max_length=10, blank=True, null=True)
    create_date = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'tb_site'


class TbStatus(models.Model):
    status_code = models.IntegerField(primary_key=True)
    status_name = models.CharField(max_length=50)
    status_desc = models.CharField(max_length=500, blank=True, null=True)
    status_type = models.CharField(max_length=100, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'tb_status'


class TbUser(models.Model):
    password = models.CharField(max_length=128)
    last_login = models.DateTimeField(blank=True, null=True)
    is_superuser = models.IntegerField()
    username = models.CharField(unique=True, max_length=30)
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=30)
    email = models.CharField(max_length=254)
    is_staff = models.IntegerField()
    is_active = models.IntegerField()
    date_joined = models.DateTimeField()
    nfc_id = models.CharField(db_column='NFC_id', max_length=100, blank=True, null=True)  # Field name made lowercase.
    ext = models.CharField(max_length=50, blank=True, null=True)
    short_number = models.CharField(max_length=50, blank=True, null=True)
    mobile_phone = models.CharField(max_length=50, blank=True, null=True)
    head = models.CharField(max_length=100, blank=True, null=True)
    sign = models.CharField(max_length=100, blank=True, null=True)
    site = models.ForeignKey(TbSite)
    status = models.ForeignKey(TbStatus)

    # def __str__(self):
    #     return self.id

    class Meta:
        managed = False
        db_table = 'tb_user'


class TbProject(models.Model):
    pid = models.IntegerField(db_column='PID', unique=True)  # Field name made lowercase.
    short_name = models.CharField(max_length=100)
    full_name = models.CharField(max_length=500)
    desc = models.CharField(max_length=1000)
    opinion = models.CharField(max_length=500, blank=True, null=True)
    http_address = models.CharField(max_length=200, blank=True, null=True)
    server_ip = models.CharField(max_length=100, blank=True, null=True)
    create_date = models.DateTimeField()
    manager = models.ForeignKey(TbUser,related_name="r_user")
    proposer = models.ForeignKey(TbUser,related_name="p_user")
    status = models.ForeignKey(TbStatus)
    have_mobile = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'tb_project'


class TbProjectRole(models.Model):
    role_name = models.CharField(max_length=100)
    role_code = models.CharField(max_length=50, blank=True, null=True)
    role_desc = models.CharField(max_length=500)
    role_desc2 = models.CharField(max_length=500, blank=True, null=True)
    create_date = models.DateTimeField()
    project = models.ForeignKey(TbProject)
    is_active = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'tb_project_role'


class TbUserRoleMap(models.Model):
    role = models.ForeignKey(TbProjectRole)
    user = models.ForeignKey(TbUser)

    class Meta:
        managed = False
        db_table = 'tb_user_role_map'


class TbFunction(models.Model):
    name = models.CharField(unique=True, max_length=50)
    parent_id = models.IntegerField(blank=True, null=True)
    code = models.CharField(max_length=50, blank=True, null=True)
    project = models.ForeignKey(TbProject)
    parent_code = models.CharField(max_length=500, blank=True, null=True)
    full_code = models.CharField(max_length=500)
    is_active = models.IntegerField()
    create_date = models.DateTimeField()
    definer = models.ForeignKey(TbUser)
    desc = models.CharField(max_length=500)
    desc2 = models.CharField(max_length=500, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'tb_function'


class TbRoleFunctionMap(models.Model):
    role = models.ForeignKey(TbProjectRole)
    function = models.ForeignKey(TbFunction)

    class Meta:
        managed = False
        db_table = 'tb_role_function_map'


class TbMenu(models.Model):
    project = models.ForeignKey('TbProject', blank=True, null=True)
    project_name = models.CharField(max_length=255, blank=True, null=True)
    menujson = models.TextField(db_column='menuJson', blank=True, null=True)  # Field name made lowercase.
    version = models.CharField(max_length=255, blank=True, null=True)
    enabled = models.IntegerField(blank=True, null=True)
    last_edit_time = models.DateTimeField(blank=True, null=True,auto_now=True)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    desc2 = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'tb_menu'


class TbMymenu(models.Model):
    user = models.ForeignKey('TbUser', blank=True, null=True)
    my_menu_json = models.TextField(blank=True, null=True)
    system_menu_json = models.TextField(blank=True, null=True)
    timeout = models.CharField(max_length=255, blank=True, null=True)
    last_edit_time = models.DateTimeField(blank=True, null=True,auto_now=True)
    mymenu_status = models.CharField(max_length=50, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    desc2 = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'tb_mymenu'








